package com.yanqu.road.server.manger.config.grandchild.talent.trigger;

import com.yanqu.road.entity.config.skill.SkillInfo;
import com.yanqu.road.entity.grandchild.GrandChildData;
import com.yanqu.road.server.manger.config.grandchild.talent.entity.*;
import com.yanqu.road.server.manger.config.grandchild.talent.enums.eGrandChildSkillEffect;
import com.yanqu.road.server.manger.config.grandchild.talent.utils.TalentUtils;

import java.util.ArrayList;
import java.util.List;

public class TalentTriggerTOO implements ITalentTrigger {

    @Override
    public TalentTriggerResult getResult(TalentTriggerParam param) {
        List<TalentTriggerSkillResult> skillResultList = new ArrayList<>();

        GrandChildData grandChild = param.getGrandChild();
        int occupation = grandChild.getOccupation();
        GrandChildTalentConditionParam condition = param.getCondition();
        int value = condition.getValue();
        boolean canTrigger = condition.getFlag().getResult(occupation, value);
        if (canTrigger) {
            List<SkillInfo> skillInfo = TalentUtils.getSkillInfo(param.getTalentInfo().getSkills(), param.getStage());
            for (SkillInfo info : skillInfo) {
                TalentTriggerSkillParam skillParam = TalentTriggerSkillParamBuilder.aTalentTriggerSkillParam()
                        .setGrandChild(param.getGrandChild())
                        .setSkillInfo(info)
                        .setLastTriggerList(param.getLastTriggerList())
                        .build();
                TalentTriggerSkillResult result = eGrandChildSkillEffect.getResult(skillParam);
                skillResultList.add(result);
            }
        }
        return TalentTriggerResultBuilder.aTalentTriggerResult()
                .setTalentId(param.getTalentInfo().getId())
                .setSkillResultList(skillResultList)
                .build();
    }
}
